package com.zzty.zzlp.dao;

import com.zzty.zzlp.entity.SelfExamTransation;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import java.util.List;

public interface SelfExamTransationMapper {
    @Select("select * from selfexamtransation where examId=#{examId} and userId=#{userId};")
    public SelfExamTransation searchSETByExamIdAndUserId(@Param("examId") Integer examId,
                                                         @Param("userId") Integer userId);

    @Update(" update selfexamtransation set totalTime = #{min} where examId = #{examId} and userId = #{userId}")
    public void updateTotalTime(@Param("examId") Integer examId, @Param("userId") Integer userId,
                                @Param("min") Integer min);

    @Update("update selfexamtransation set startTime=#{startTime} where examId=#{examId} and userId=#{userId}")
    public void updateStartTime(@Param("examId") Integer examId, @Param("userId") Integer userId,
                                @Param("startTime") String startTime);

    @Update("update selfexamtransation set answers=#{answers} where examId=#{examId} and userId=#{userId}")
    public void updateAnswers(@Param("examId") Integer examId, @Param("userId") Integer userId,
                              @Param("answers") String answers);

    @Update("update selfexamtransation set isValid=#{isValid} where examId=#{examId} and userId=#{userId}")
    public void updateIsValid(@Param("examId") Integer examId, @Param("userId") Integer userId,
                              @Param("isValid") Integer isValid);

    // @Select("select userId from selfexamtransation where examId=#{examId}")
    // public List<Integer> searchUseridByExamid(@Param("examId") Integer
    // examId);

    @Select("select * from selfexamtransation where examId=#{examId}")
    public List<SelfExamTransation> searchSETByExamId(@Param("examId") Integer examId);

    @Update("update selfexamtransation set score=#{score} where examId=#{examId} and userId=#{userId}")
    public void updateScore(@Param("examId") Integer examId, @Param("userId") Integer userId,
                            @Param("score") String score);

    @Update("update selfexamtransation set comment=#{comment} where examId=#{examId} and userId=#{userId}")
    public void updateComment(@Param("examId") Integer examId, @Param("userId") Integer userId,
                              @Param("comment") String comment);

    @Select("select comment from selfexamtransation where examId = #{examId} and userId = #{userId}")
    public String searchComment(@Param("examId") Integer examId, @Param("userId") Integer userId);

    @Insert("insert into selfexamtransation(examId,userId) values (#{examId},#{userId})")
    public void addSelfExamTransation(SelfExamTransation set);

    @Update("update selfexamtransation set rank=1 where examId=#{examId} and score='A'")
    public void updateRank(@Param("examId") Integer examId);

    @Select("select userId from selfexamtransation where examId=#{examId} and score='A'")
    public Integer searchWinnerId(@Param("examId") Integer examId);


}
